<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('退出决策') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('项目名称')" prop="dealName">
        <el-input v-model="queryParams.dealName" :placeholder="$t('项目名称')" size="small" @keyup.enter.native="queryHandle" />
      </el-form-item>
      <el-form-item :label="$t('行业')" prop="dealIndustry">
        <dictSelect
          v-model="queryParams.dealIndustry"
          :clearable="true"
          dictionary="deal_industry"
        />
      </el-form-item>
      <el-form-item :label="$t('投资主体')" prop="investmentNames">
        <el-input v-model="queryParams.investmentNames" :placeholder="$t('投资主体')" size="small" @keyup.enter.native="queryHandle" />
      </el-form-item>
      <el-form-item :label="$t('负责人')" prop="teamNames">
        <el-input v-model="queryParams.teamNames" :placeholder="$t('负责人')" size="small" @keyup.enter.native="queryHandle" />
      </el-form-item>
      <el-form-item :label="$t('优先退出方式')" prop="priorExitWay">
        <dictSelect
          v-model="queryParams.priorExitWay"
          :clearable="true"
          dictionary="exit_plan_item"
        />
      </el-form-item>
      <el-form-item :label="$t('备选退出方式')" prop="spareExitWay">
        <dictSelect
          v-model="queryParams.spareExitWay"
          :clearable="true"
          dictionary="exit_plan_item"
        />
      </el-form-item>
      <el-form-item :label="$t('本周进展-截止日期')" prop="endDate">
        <el-date-picker
          v-model="queryParams.endDate"
          type="date"
          placeholder="截止日期"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
        <el-button type="warning" icon="el-icon-download" size="mini" @click="exportHandle">{{ $t("导出") }}</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" tooltip-effect="darkTable" :data="exitIndustryList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('项目名称')" align="center" prop="dealName" :show-overflow-tooltip="true" min-width="150px" />
      <el-table-column :label="$t('行业')" align="center" prop="dealIndustry" :formatter="industryFormat" show-overflow-tooltip min-width="130" />
      <el-table-column :label="$t('投资主体')" align="center" prop="investmentNames" show-overflow-tooltip min-width="180" />
      <el-table-column :label="$t('负责人')" align="center" prop="teamNames" show-overflow-tooltip min-width="180" />
      <el-table-column :label="$t('优先退出方式')" align="center" prop="priorExitWay" :formatter="priorFormat" show-overflow-tooltip min-width="130" />
      <el-table-column :label="$t('备选退出方式')" align="center" prop="spareExitWay" :formatter="spareFormat" show-overflow-tooltip min-width="130" />
      <el-table-column :label="$t('下一步工作计划')" align="center" prop="nextPlan" show-overflow-tooltip min-width="140" />
      <el-table-column :label="$t('本周进展')" align="center" prop="weekProgress" show-overflow-tooltip min-width="180" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { industryExitReport } from '@/api/sass/kaihui/exit/kaiHuiDealExit'
import { getToken } from '@/utils/auth'
import axios from 'axios'

export default {
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 退出申请表格数据
      exitIndustryList: [],
      // 退出方式字典
      exitWayOptions: [],
      // 项目行业
      industryOptions: [],
      // 查询参数
      queryParams: {
        dealName: undefined,
        investmentNames: undefined,
        teamNames: undefined,
        priorExitWay: undefined,
        spareExitWay: undefined,
        dealIndustry: undefined,
        endDate: undefined,
        pageNum: 1,
        pageSize: 10
      }
    }
  },
  created() {
    this.getList()
    this.getDicts('exit_plan_item').then(response => {
      this.exitWayOptions = response.data
    })
    this.getDicts('deal_industry').then(response => {
      this.industryOptions = response.data
    })
  },
  methods: {
    /** 查询退出申请列表 */
    getList() {
      this.loading = true
      industryExitReport(this.queryParams).then(response => {
        this.exitIndustryList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 退出方式字典翻译
    // eslint-disable-next-line no-unused-vars
    priorFormat(row) {
      return this.selectDictLabel(this.exitWayOptions, row.priorExitWay)
    },
    spareFormat(row) {
      return this.selectDictLabel(this.exitWayOptions, row.spareExitWay)
    },
    nextPlanFormat(row) {
      return this.selectDictLabel(this.exitWayOptions, row.nextPlan)
    },
    industryFormat(row) {
      return this.selectDictLabel(this.industryOptions, row.dealIndustry)
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
    },
    /** 导出按钮操作 */
    exportHandle() {
      this.loading = true
      // 准备下载
      axios({
        method: 'post',
        url: process.env.VUE_APP_BASE_API + '/exitReport/exportIndustryReport',
        data: this.queryParams,
        responseType: 'blob',
        headers: { 'Authorization': 'Bearer ' + getToken() }
      }).then(res => {
        const blob = res.data
        const reader = new FileReader()
        reader.readAsDataURL(blob)
        reader.onload = (e) => {
          const a = document.createElement('a')
          // 获取选择的基金名称
          const fileName = '【行业退出计划报表】'
          a.download = fileName + `.xlsx`
          a.href = e.target.result
          document.body.appendChild(a)
          a.click()
          document.body.removeChild(a)
          this.loading = false
        }
      })
    }
  }
}
</script>
